export interface RequestOptions {
}

export interface Response {
  status: number;
  statusText: string;
  headers: Headers;
  body: any;
}

export interface Requestor {
  get(url: string, options?: RequestOptions): Promise<Response>;
  post(url: string, options?: RequestOptions): Promise<Response>;
  put(url: string, options?: RequestOptions): Promise<Response>;
  delete(url: string, options?: RequestOptions): Promise<Response>;
}

let req: Requestor;

export function inject(request: Requestor) {
  req = request;
}

export function useRequestor() {
  return req
}

// 创建重试请求
export function createRetryRequest(retryCount: number = 3): Requestor {
  req = useRequestor()
  // ... 重试的相应配置
  return req
}

// 创建并发请求
export function createConcurrentRequest(maxConcurrent: number = 3): Requestor {
  req = useRequestor()
  // ... 并发请求的相应配置
  return req
}

// 创建缓存请求
export function createCacheRequest(cacheTime: number = 1000 * 60 * 5): Requestor {
  req = useRequestor()
  // ... 缓存请求的相应配置
  return req
}
